﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Hsp.Auto.Common.Data
{
    /// <summary>
    /// 枚举帮助类
    /// </summary>
    public static class EnumHelper
    {
        public static T GetAttributeOfType<T>(this Enum enumVal) where T : Attribute
        {
            var typeInfo = enumVal.GetType().GetTypeInfo();
            var mi = typeInfo.DeclaredMembers.First(x => x.Name == enumVal.ToString());
            return mi.GetCustomAttribute<T>();
        }

        public static string GetDescription(this Enum enumVal)
        {
            var attr = GetAttributeOfType<DisplayAttribute>(enumVal);
            return attr != null ? attr.Description : string.Empty;
        }
    }

    /// <summary>
    /// 数据库类型
    /// </summary>
    public enum DBType
    {
        /// <summary>
        /// SqlServer数据库
        /// </summary>
        SqlServer,
        /// <summary>
        /// MySql数据库
        /// </summary>
        MySql,
        /// <summary>
        /// Oracle数据库(内置使用 Oracle.ManagedDataAccess 客户端)
        /// </summary>
        //Oracle,
        /// <summary>
        /// Oracle数据库(内置使用 DDTek.Oracle 客户端)
        /// </summary>
        //OracleDDTek,
        /// <summary>
        /// PostgreSql数据库
        /// </summary>
        //PostgreSql,
        /// <summary>
        /// SQLite数据库
        /// </summary>
        SQLite,
        /// <summary>
        /// DB2数据库
        /// </summary>
        //DB2
    }

}
